home *** CD-ROM | disk | FTP | other *** search
-
-
-
- OPENDIR(3) MINTLIB LIBRARY FUNCTIONS OPENDIR(3)
-
-
- N✓NA✓AM✓ME✓E
- directory, opendir, readdir, telldir, seekdir, rewinddir,
- closedir - directory operations
-
- S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
- #include <dirent.h>
-
- DIR *opendir(const char *dirname);
-
- struct dirent *readdir(DIR *dirp);
-
- off_t telldir(DIR *dirp);
-
- void seekdir(DIR *dirp, off_t loc);
-
- void rewinddir(DIR *dirp);
-
- int closedir(DIR *dirp);
-
- D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
- opendir opens the directory named by dirname and associ-
- ates a directory stream with it. opendir returns a pointer
- to be used to identify the directory stream in subsequent
- operations. A NULL pointer is returned if dirname cannot
- be accessed or is not a directory, or if it cannot malloc
- enough memory to hold the whole thing.
-
- readdir returns a pointer to the next directory entry. It
- returns NULL upon reaching the end of the directory or
- detecting and invalid seekdir operation.
-
- telldir returns the current location associated with the
- named directory stream.
-
- seekdir sets the position of the next readdir operation on
- the directory stream. The new position reverts to the one
- associated with the directory stream when the telldir
- operation was performed. Values returned by telldir are
- good only for the lifetime of the DIR pointer from which
- they are derived. If the directory is closed and then
- reopened, the telldir value may be invalidated due to
- changes in the directory.
-
- rewinddir resets the position of the named directory
- stream to the beginning of the directory. It also causes
- the directory stream to refer to the current state of the
- corresponding directory, as a call to opendir would have
- done.
-
- closedir closes the named directory stream and frees the
- structure associated with the DIR pointer.
-
- R✓RE✓ET✓TU✓UR✓RN✓N V✓VA✓AL✓LU✓UE✓ES✓S
- opendir returns a pointer of type DIR on success. On
-
-
-
- MiNT docs 0.1 3 March 1993 1
-
-
-
-
-
- OPENDIR(3) MINTLIB LIBRARY FUNCTIONS OPENDIR(3)
-
-
- failure, it returns NULL and sets errno to indicate the
- error.
-
- readdir returns a pointer of object type struct dirent on
- success. On failure, it returns NULL and sets errno to
- indicate the error. When the end of the directory is
- encountered, readdir returns NULL and leaves errno
- unchanged. The dirent structure is defined in <dirent.h>
- and contains the following fields of interest:
- struct dirent
- {
- long d_ino; /* garbage under TOS emulation */
- off_t d_off; /* position in directory */
- short d_reclen; /* length of d_name */
- ... /* various TOS-emulation fields */
- char *d_name; /* name of the current file */
- };
-
- closedir returns 0 on succes, EIHNDL on failure.
-
- telldir returns the current location associated with the
- specified directory stream.
-
- E✓EX✓XA✓AM✓MP✓PL✓LE✓E
- Sample code which searches a directory for entry `name' is:
-
- dirp = opendir(".");
- for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp))
- if (!strcmp(dp->d_name, name))
- {
- closedir(dirp);
- return (FOUND);
- }
- closedir(dirp);
- return (NOT_FOUND);
-
- S✓SE✓EE✓E A✓AL✓LS✓SO✓O
- D✓Do✓op✓pe✓en✓nd✓di✓ir✓r(✓(2✓2)✓),✓, D✓Dr✓re✓ea✓ad✓dd✓di✓ir✓r(✓(2✓2)✓),✓, D✓Dc✓cl✓lo✓os✓se✓ed✓di✓ir✓r(✓(2✓2)✓)
-
- N✓NO✓OT✓TE✓ES✓S
- As memory is allocated at every call to opendir, every
- call to opendir should be matched by a corresponding call
- to closedir.
-
- When MiNT is not active, readdir calls are emulated under
- TOS. When that happens, various fields in the dirent
- structure are used that are undefined when MiNT is active.
- It is therefore advisable not to use those fields.
-
- Because of an error in the mintlibs and a change in MiNT
- 0.97, programs using readdir from the mintlibs pl 24 or
- below will die in MiNT 0.97 or higher.
-
-
-
-
-
- MiNT docs 0.1 3 March 1993 2
-
-
-